package com.patentbackend.patentmanage.utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;

@Component
public class EmailUtils {

    @Autowired
    private JavaMailSender mailSender;

    public void sendSimpleMessage(String to, String subject, String text) {
        SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom("noreply@patentmanager.com");
        message.setTo(to);
        message.setSubject(subject);
        message.setText(text);
        mailSender.send(message);
    }

    public void sendRegistrationConfirmationEmail(String to, String username) {
        String subject = "专利管理系统 - 注册成功";
        String text = "尊敬的 " + username + ":\n\n" +
                "您已成功注册专利管理系统账户。\n" +
                "请等待管理员审核，审核通过后您将收到通知邮件。\n\n" +
                "专利管理系统\n" +
                "https://patentmanager.com";

        sendSimpleMessage(to, subject, text);
    }

    public void sendVerificationResultEmail(String to, String username, boolean approved) {
        String subject = "专利管理系统 - 账号审核结果";
        String text;

        if (approved) {
            text = "尊敬的 " + username + ":\n\n" +
                    "您的专利管理系统账户已通过审核，现在可以登录系统。\n\n" +
                    "专利管理系统\n" +
                    "https://patentmanager.com";
        } else {
            text = "尊敬的 " + username + ":\n\n" +
                    "很遗憾，您的专利管理系统账户审核未通过。\n" +
                    "如有疑问，请联系管理员。\n\n" +
                    "专利管理系统\n" +
                    "https://patentmanager.com";
        }

        sendSimpleMessage(to, subject, text);
    }

    public void sendAnnualFeeReminderEmail(String to, String patentTitle, String dueDate) {
        String subject = "专利管理系统 - 年费提醒";
        String text = "尊敬的用户:\n\n" +
                "您的专利 \"" + patentTitle + "\" 的年费即将到期，截止日期为 " + dueDate + "。\n" +
                "请及时缴纳年费以维持专利有效性。\n\n" +
                "专利管理系统\n" +
                "https://patentmanager.com";

        sendSimpleMessage(to, subject, text);
    }
}